//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.spring.schedule_system.dengxiaojiao.util;


import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.net.BindException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.prefs.BackingStoreException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil {
    public static StringUtil.SaveOrUpdate Save;
    public static StringUtil.SaveOrUpdate Update;

    public StringUtil() {
    }

    public static Boolean IsEmptyOrNull(Object obj) {
        if (obj == null) {
            return true;
        } else if ("".equals(obj)) {
            return true;
        } else if ("null".equals(obj)) {
            return true;
        } else {
            if (obj instanceof String) {
                if (((String)obj).length() == 0) {
                    return true;
                }
            } else if (obj instanceof Collection) {
                if (((Collection)obj).size() == 0) {
                    return true;
                }
            } else if (obj instanceof Map && ((Map)obj).size() == 0) {
                return true;
            }

            return false;
        }
    }

    public static String getGUID() {
        return LyIdUtils.genId();
    }

    public static void isDateTimeValidTip(String objType, String obj, String tip) {
        try {
            if (!IsEmptyOrNull(obj) && !IsEmptyOrNull(objType)) {
                if ("1".equals(objType)) {
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                    format.setLenient(false);
                    format.parse(obj);
                }

                if ("2".equals(objType)) {
                    LocalDateTime.parse(obj, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
                }
            }

        } catch (Exception var4) {

        }
    }

    public static void isDateTimeValidTip(String obj, String tip) {
        try {
            if (!IsEmptyOrNull(obj)) {
                LocalDateTime.parse(obj, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            }

        } catch (Exception var3) {

        }
    }

    public static void notEmptyTip(Object obj, String tip) {
        if (IsEmptyOrNull(obj)) {

        }
    }

    public static void notEmptyTip(Object obj1, Object obj2, String tip) {
        if (IsEmptyOrNull(obj1) && IsEmptyOrNull(obj2)) {

        }
    }

    public static <T> void sortByMethod(List<T> list, final String method, final boolean reverseFlag) {
        Collections.sort(list, new Comparator<Object>() {
            public int compare(Object arg1, Object arg2) {
                int result = 0;

                try {
                    Method m1 = arg1.getClass().getMethod(method, (Class[])null);
                    Method m2 = arg2.getClass().getMethod(method, (Class[])null);
                    Object obj1 = m1.invoke(arg1, (Object[])null);
                    Object obj2 = m2.invoke(arg2, (Object[])null);
                    if (obj1 instanceof String) {
                        result = obj1.toString().compareTo(obj2.toString());
                    } else if (obj1 instanceof Date) {
                        long l = ((Date)obj1).getTime() - ((Date)obj2).getTime();
                        if (l > 0L) {
                            result = 1;
                        } else if (l < 0L) {
                            result = -1;
                        } else {
                            result = 0;
                        }
                    } else if (obj1 instanceof Integer) {
                        result = (Integer)obj1 - (Integer)obj2;
                    } else if (obj1 instanceof Long) {
                        Long o1 = (Long)obj1;
                        Long o2 = (Long)obj2;
                        result = Integer.parseInt(o1.toString()) - Integer.parseInt(o2.toString());
                    } else if (obj1 instanceof BigDecimal) {
                        result = (new BigDecimal(obj1.toString())).subtract(new BigDecimal(obj2.toString())).intValue();
                    } else {
                        result = obj1.toString().compareTo(obj2.toString());
                        System.err.println("MySortList.sortByMethod方法接受到不可识别的对象类型，转换为字符串后比较返回...");
                    }

                    if (reverseFlag) {
                        result = -result;
                    }
                } catch (NoSuchMethodException var10) {
                    System.out.println(var10.getMessage());
                } catch (IllegalAccessException var11) {
                    System.out.println(var11.getMessage());
                } catch (InvocationTargetException var12) {
                    System.out.println(var12.getMessage());
                }

                return result;
            }
        });
    }

    public static int getLength(String obj) {
        int valueLength = 0;
        String chinese = "[Α-￥]";

        for(int i = 0; i < obj.length(); ++i) {
            String temp = obj.substring(i, i + 1);
            if (temp.matches(chinese)) {
                valueLength += 2;
            } else {
                ++valueLength;
            }
        }

        return valueLength;
    }

    public static void isPhoneValidTip(String obj, String tip) {
        String regex = "((\\d{11})|^((\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})|(\\d{4}|\\d{3})-(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1})|(\\d{7,8})-(\\d{4}|\\d{3}|\\d{2}|\\d{1}))$)";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(obj);
        boolean isMatch = m.matches();
        if (!isMatch) {

        }
    }

    public static void isMailValidTip(String obj, String tip) {
        String regex = "^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(obj);
        boolean isMatch = m.matches();
        if (!isMatch) {

        }
    }

    public static void isZipValidTip(String obj, String tip) {
        String regex = "[1-9]\\d{5}(?!\\d)";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(obj);
        boolean isMatch = m.matches();
        if (!isMatch) {

        }
    }

    public static <T> T initUserInfo(T object, StringUtil.SaveOrUpdate enums) {
        return initUserInfo(object, enums, (BusinessContext)null);
    }

    public static <T> T initUserInfo(T object, StringUtil.SaveOrUpdate enums, BusinessContext busiContext) {
        if (object == null) {
            return null;
        } else {
            BusinessContext businessContext = busiContext == null ? BusinessContext.getBusinessContext() : busiContext;
            if (object instanceof Map) {
                Map<String, String> map = (Map)object;
                if (enums.equals(StringUtil.SaveOrUpdate.Save)) {
                    map.put("oemId", businessContext.getOemId());
                    map.put("groupId", businessContext.getGroupId());
                    map.put("creatorName", businessContext.getEmpName());
                    map.put("createdName", businessContext.getEmpName());
                    map.put("modifierName", businessContext.getEmpName());
                    map.put("modifier", businessContext.getUserId());
                    map.put("creator", businessContext.getUserId());
                    map.put("updateControlId", LyIdUtils.genId());
                    map.put("createdDate", LocalDateTime.now().toString());
                    map.put("lastUpdatedDate", LocalDateTime.now().toString());
                } else {
                    map.put("lastUpdatedDate", LocalDateTime.now().toString());
                    map.put("modifier", businessContext.getUserId());
                    map.put("modifierName", businessContext.getEmpName());
                    map.put("modifyName", businessContext.getEmpName());
                    map.put("updateControlId", LyIdUtils.genId());
                }

                return object;
            } else {
                Class clazz = object.getClass();

                try {
                    Method method4 = null;
                    Method method5 = null;
                    Method method12 = null;
                    switch(enums) {
                    case Save:
                        Method getMethod = clazz.getMethod("getOemId");
                        if (IsEmptyOrNull(getMethod.invoke(object))) {
                            Method method = clazz.getMethod("setOemId", String.class);
                            method.invoke(object, businessContext.getOemId());
                        }

                        Method getMethod1 = clazz.getMethod("getGroupId");
                        if (IsEmptyOrNull(getMethod1.invoke(object))) {
                            Method method2 = clazz.getMethod("setGroupId", String.class);
                            method2.invoke(object, businessContext.getGroupId());
                        }

                        try {
                            method4 = clazz.getMethod("setCreatorName", String.class);
                            method4.invoke(object, businessContext.getEmpName());
                        } catch (Exception var26) {
                        }

                        try {
                            if (method4 == null) {
                                method4 = clazz.getMethod("setCreatedName", String.class);
                                method4.invoke(object, businessContext.getEmpName());
                            }
                        } catch (Exception var25) {
                        }

                        try {
                            method5 = clazz.getMethod("setModifierName", String.class);
                            method5.invoke(object, businessContext.getEmpName());
                        } catch (Exception var24) {
                        }

                        try {
                            if (method5 == null) {
                                method5 = clazz.getMethod("setModifyName", String.class);
                                method5.invoke(object, businessContext.getEmpName());
                            }
                        } catch (Exception var23) {
                        }

                        Method method6 = clazz.getMethod("setModifier", String.class);
                        method6.invoke(object, businessContext.getUserId());
                        Method method7 = clazz.getMethod("setCreator", String.class);
                        method7.invoke(object, businessContext.getUserId());
                        Method method8 = clazz.getMethod("setUpdateControlId", String.class);
                        method8.invoke(object, LyIdUtils.genId());
                        Method method9 = clazz.getMethod("setCreatedDate", LocalDateTime.class);
                        method9.invoke(object, LocalDateTime.now());
                        Method method10 = clazz.getMethod("setLastUpdatedDate", LocalDateTime.class);
                        method10.invoke(object, LocalDateTime.now());
                        break;
                    case Update:
                        Method method11 = clazz.getMethod("setLastUpdatedDate", LocalDateTime.class);
                        method11.invoke(object, LocalDateTime.now());
                        Method method13 = clazz.getMethod("setModifier", String.class);
                        method13.invoke(object, businessContext.getUserId());

                        try {
                            method12 = clazz.getMethod("setModifierName", String.class);
                            method12.invoke(object, businessContext.getEmpName());
                        } catch (Exception var22) {
                        }

                        try {
                            if (method5 == null) {
                                method5 = clazz.getMethod("setModifyName", String.class);
                                method5.invoke(object, businessContext.getEmpName());
                            }
                        } catch (Exception var21) {
                        }

                        Method method17 = clazz.getMethod("setUpdateControlId", String.class);
                        method17.invoke(object, LyIdUtils.genId());
                    }

                    return object;
                } catch (Exception var27) {
                    throw new RuntimeException(var27);
                }
            }
        }
    }

    public static String transToString(Object obj) {
        if ("null".equals(String.valueOf(obj))) {
            obj = "";
        }

        return String.valueOf(obj);
    }

    public static Map<String, Object> entityToMap(Object object) {
        Map<String, Object> map = new HashMap();
        Field[] var2 = object.getClass().getDeclaredFields();
        int var3 = var2.length;

        for(int var4 = 0; var4 < var3; ++var4) {
            Field field = var2[var4];

            try {
                boolean flag = field.isAccessible();
                field.setAccessible(true);
                Object o = field.get(object);
                map.put(field.getName(), o);
                field.setAccessible(flag);
            } catch (Exception var8) {
                System.out.println(var8.getMessage());
            }
        }

        return map;
    }

    public static <T> List<T> objetcToList(Object obj, Class<T> clazz) {
        List<T> result = new ArrayList();
        if (!(obj instanceof List)) {
            return null;
        } else {
            Iterator var3 = ((List)obj).iterator();

            while(var3.hasNext()) {
                Object o = var3.next();
                result.add(clazz.cast(o));
            }

            return result;
        }
    }

    public static void checkIpage(int pageIndex, int pageSize) {
        if (!IsEmptyOrNull(pageIndex) && 0 != pageIndex) {
            if (IsEmptyOrNull(pageSize) || 0 == pageSize) {

            }
        } else {

        }
    }

    public static boolean isNumber(String str) {
        try {
            Integer.parseInt(str);
            return true;
        } catch (NumberFormatException var2) {
            return false;
        }
    }

    public static Boolean isPositiveNum(String str) {
        String regex = "^([0-9][0-9]{0,3}|10000)$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(str);
        boolean isMatch = m.matches();
        return !isMatch ? false : true;
    }

    public static Boolean isPositiveDecimalNum(String str) {
        String regex = "^100000$|^([1-9][0-9]{0,4}|0)([.][0-9]{1,4})?$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(str);
        boolean isMatch = m.matches();
        return !isMatch ? false : true;
    }

    public static Boolean isPercentage(String str) {
        String regex = "^([1-9]|[1-9][0-9]|[1-9][0-9][0-9])?\\d(\\.\\d\\d?)?%$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(str);
        boolean isMatch = m.matches();
        return !isMatch ? false : true;
    }

    public static int convertObjToInt(Object obj) {
        return IsEmptyOrNull(obj) ? 0 : Integer.valueOf(String.valueOf(obj));
    }

    public static <T> List<List<T>> splitListByCount(List<T> list, int count) {
        List<List<T>> listAll = new ArrayList();
        int size = list.size();
        if (size > count) {
            int absInt = Math.abs(size / count);
            if (size - absInt * count > 0) {
                listAll.add(list.subList(absInt * count, size));
            }

            for(int i = 1; i < absInt + 1; ++i) {
                listAll.add(list.subList((i - 1) * count, i * count));
            }
        } else {
            listAll.add(list);
        }

        return listAll;
    }



    public static String valueOf(Object obj) {
        return obj == null ? "" : String.valueOf(obj);
    }

    public static String getYesNoName(String code) {
        return "1".equals(code) ? "是" : "否";
    }

    public static String substr(String str, int maxLength) {
        return IsEmptyOrNull(str) ? str : str.substring(0, str.length() < maxLength ? str.length() : maxLength);
    }

    public static String getDayOfWeekEn(LocalDateTime dateTime) {
        int value = dateTime.getDayOfWeek().getValue();
        String dayOfWeekEn = "";
        switch(value) {
        case 1:
            dayOfWeekEn = "Monday";
            break;
        case 2:
            dayOfWeekEn = "Tuesday";
            break;
        case 3:
            dayOfWeekEn = "Wednesday";
            break;
        case 4:
            dayOfWeekEn = "Thursday";
            break;
        case 5:
            dayOfWeekEn = "Friday";
            break;
        case 6:
            dayOfWeekEn = "Saturday";
            break;
        case 7:
            dayOfWeekEn = "Sunday";
        }

        return dayOfWeekEn;
    }

    public static String getDayOfWeekEn() {
        return getDayOfWeekEn(LocalDateTime.now());
    }

    static {
        Save = StringUtil.SaveOrUpdate.Save;
        Update = StringUtil.SaveOrUpdate.Update;
    }

    public static enum SaveOrUpdate {
        Save,
        Update;

        private SaveOrUpdate() {
        }
    }
}
